package com.turnengine.client.global.announcement.command;

import com.turnengine.client.global.game.enums.GameLevel;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Get Announcement List.
 */
public class GetAnnouncementList implements IGetAnnouncementList {

	/** The command id. */
	public static final short COMMAND_ID = 103;

	/** The game level id. */
	private int gameLevelId;
	/** The game level. */
	private GameLevel gameLevel;

	/**
	 * Creates a new Get Announcement List.
	 */
	public GetAnnouncementList() {
	}

	/**
	 * Creates a new Get Announcement List.
	 * @param gameLevelId the game level id
	 * @param gameLevel the game level
	 */
	public GetAnnouncementList(int gameLevelId, GameLevel gameLevel) {
		setGameLevelId(gameLevelId);
		setGameLevel(gameLevel);
	}

	/**
	 * Creates a new Get Announcement List.
	 * @param iGetAnnouncementList the i get announcement list
	 */
	public GetAnnouncementList(IGetAnnouncementList iGetAnnouncementList) {
		setGameLevelId(iGetAnnouncementList.getGameLevelId());
		setGameLevel(iGetAnnouncementList.getGameLevel());
	}

	/**
	 * Returns the game level id.
	 * @return the game level id.
	 */
	public int getGameLevelId() {
		return gameLevelId;
	}

	/**
	 * Returns the game level.
	 * @return the game level.
	 */
	public GameLevel getGameLevel() {
		return gameLevel;
	}

	/**
	 * Sets the game level id.
	 * @param gameLevelId the game level id to set.
	 */
	public void setGameLevelId(int gameLevelId) {
		this.gameLevelId = gameLevelId;
	}

	/**
	 * Sets the game level.
	 * @param gameLevel the game level to set.
	 */
	public void setGameLevel(GameLevel gameLevel) {
		if (gameLevel == null) {
			throw new NullPointerException("gameLevel");
		}
		this.gameLevel = gameLevel;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(17, 37);
		hash.append(gameLevelId);
		hash.append(gameLevel);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GetAnnouncementList) {
			GetAnnouncementList compare = (GetAnnouncementList) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.gameLevelId, compare.gameLevelId);
			equals.append(this.gameLevel, compare.gameLevel);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGetAnnouncementList compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.gameLevelId, compare.getGameLevelId());
		builder.append(this.gameLevel, compare.getGameLevel());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("gameLevelId", gameLevelId);
		if (gameLevel != null) {
			string.append("gameLevel", gameLevel);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
